package com.hx.petsever.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hx.petsever.entity.adminAccount;
import com.hx.petsever.mapper.AdminMapper;
import com.hx.petsever.service.AdminService;
import com.hx.petsever.utils.JWTUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, adminAccount> implements AdminService {

    @Autowired
    AdminMapper adminMapper;

    @Override
    public Map login(adminAccount account) {
        Map<String, Object> map = new HashMap<>();
        adminAccount user1 = adminMapper.login(account.getUsername(), account.getPassword());
        System.out.println(account);
        if (user1 == null)
            return null;
        else {
            Map<String, Object> payload = new HashMap<>();
            payload.put("id", user1.getUserid());
            payload.put("username", user1.getUsername());
            //生成JWT的令牌
            String token = JWTUtils.getToken(payload);
            map.put("state", true);
            map.put("msg", "认证成功");
            map.put("token", token);//响应token
            map.put("username", user1.getUsername());
            return map;
        }
    }
}
